function WavefrontManager()
{
	WavefrontManager.imagesReady = null;

	this.filenames = new Array();
	this.images = new Array();
	this.stack = new Array();

	WavefrontManager.nimages = 0;
	WavefrontManager.nfile = 0;
}

WavefrontManager.prototype.add = function(filename)
{
	this.images.push(new Array());
	this.filenames.push(filename);
}

WavefrontManager.prototype.addImage = function(filename)
{
	var image = new Image();
	this.images[this.images.length-1].push(image);

	WavefrontManager.nimages += 1;
	image.src= filename;

	image.onload = function()
		{
			if((--WavefrontManager.nimages) == 0)
			{
				WavefrontManager.imagesReady();
			}
		}
}

WavefrontManager.prototype.finish = function(next)
{

	Wavefront.allLoaded = next;

	Wavefront.nfile = this.filenames.length;
	var nfile = Wavefront.nfile;

	for(var i = 0; i < nfile; i++)
	{
		var wavefront = new Wavefront(this.filenames[i]);
		wavefront.setTextures(this.images[i]);
		this.stack.push(wavefront);
		wavefront.load();
	}
}
